package com.wly.datapool.bullet
{
	import com.wly.ActiveManager;
	import com.wly.datapool.define.DirDefine;
	import com.wly.datapool.monster.MonsterInfo;
	import com.wly.dynamicc.DynamicManager;
	import com.wly.dynamicc.DynamicObject;
	import com.wly.utils.MyPoint;
	
	import flash.display.MovieClip;

	public class BulletInfo
	{
		public var bulletBase:BulletStatic;
		private var _target:MonsterInfo;
		public var attack:int;
		public var speed:int;
		public var activeKey:int;
		private var _model:MovieClip;
		private var dynamicObj:DynamicObject;
		
		public function BulletInfo(modelIndex:int)
		{
			var cls:Class;
			bulletBase = BulletPool.getInstance().getBulletByIndex(modelIndex);
			cls = bulletBase.modelCls;
			_model = new cls;
		}
		
		public function start():void
		{
			dynamicObj = new DynamicObject;
			dynamicObj.action = onTick;
			DynamicManager.getInstance().registerObj(dynamicObj);
		}
		
		public function get model():MovieClip
		{
			return _model;
		}
		
		public function get x():int
		{
			return _model.x;
		}
		
		public function get y():int
		{
			return _model.y;
		}
		
		public function destory():void
		{
			DynamicManager.getInstance().unRegisterObj(dynamicObj);
			ActiveManager.getInstance().removeBullet(this);
		}
		
		public function onTick():void
		{
			if(_target && _target.isAlive)
			{
				var speedPt:MyPoint = DirDefine.caculateSpeed(new MyPoint(x,y), new MyPoint(_target.centerX, _target.centerY), speed);
				_model.x += speedPt.x;
				_model.y += speedPt.y;
			}
			else
			{
				destory();
			}
		}
		
		public function set targetMonster(monster:MonsterInfo):void
		{
			_target = monster;
		}
		
		public function get targetMonster():MonsterInfo
		{
			return _target;
		}
	}
}